import 'dart:io';

import 'package:bwt_ad_flutter/BwtAdCore.dart';
import 'package:bwt_ad_flutter/ad/widget/serviceWidget/BwtServiceAd.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';

class BwtServiceAdWidget extends StatefulWidget {
  final BwtServiceAd bwtServiceAd;
  final String viewType;
  const BwtServiceAdWidget(
      {Key? key, required this.bwtServiceAd, required this.viewType})
      : super(key: key);

  @override
  State<BwtServiceAdWidget> createState() => _BwtServiceAdWidgetState();
}

class _BwtServiceAdWidgetState extends State<BwtServiceAdWidget> {
  @override
  Widget build(BuildContext context) {
    var creationParams = {
      BwtAdCore.keyAdLoaderId: widget.bwtServiceAd.adLoaderId,
      BwtAdCore.keyAdId: widget.bwtServiceAd.adId,
      BwtAdCore.keyAdWidth: widget.bwtServiceAd.adWidth,
      BwtAdCore.keyAdHeight: widget.bwtServiceAd.adHeight,
    };
    return Container(
      width: widget.bwtServiceAd.adWidth,
      height: widget.bwtServiceAd.adHeight,
      constraints: BoxConstraints(maxWidth: widget.bwtServiceAd.adWidth),
      child: Platform.isAndroid
          ? AndroidView(
              viewType: widget.viewType,
              creationParams: creationParams,
              creationParamsCodec: const StandardMessageCodec(),
            )
          : UiKitView(
              viewType: widget.viewType,
              creationParams: creationParams,
              creationParamsCodec: const StandardMessageCodec(),
            ),
    );
  }
}
